

import router from "./index";
export const getDynamiMenuRouter = (routerList) => {
    if (routerList && routerList.length > 0) {
        //已经登录获取到路由数据
        let flatList = getFlatList(routerList)
        let data = getTestList(flatList, router.options.routes)
        // console.log('data', data);
        return data
    }
}
const getFlatList = (array) => {
    let flatList = []
    function flattenTree(node) {
        // 将当前节点添加到扁平化的数组中
        flatList.push(node);
        // 如果当前节点有子节点，则递归地处理子节点
        if (node.son) {
            node.son.forEach((child) => {
                flattenTree(child);
            });
        }
    }
    // 遍历数组中的每个树形结构对象，并对其进行扁平化
    array.forEach((node) => {
        flattenTree(node);
    });
    // console.log('flatList', flatList);
    return flatList
}
const getTestList = (routerList, allRouterList) => {
    let list = []
    allRouterList.forEach(item => {
        if (item.children && item.children.length > 0) {
            let data = getTestList(routerList, item.children)
            if (data.length > 0) {
                list.push({ ...item, children: data })
            }
        } else {
            // if (routerList.find(key => key.url === item.path)) {
            //     list.push(routerList.find(key => key.url === item.path))
            // }
            if (routerList.find(key => key.url === item.path)) {
                if (routerList.find(key => key.url === item.path).url == item.path)
                    list.push(item)
            }
        }
    })
    // console.log('list', list);
    return list
}